<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>订单管理</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/bootstrap/css/bootstrap.min.css">
    <script src="${pageContext.request.contextPath}/bootstrap/js/jquery-2.1.0.min.js"></script>
    <script src="${pageContext.request.contextPath}/bootstrap/js/bootstrap.min.js"></script>
</head>
<body>
${collections}
    <div class="container">
        <h1>订单管理</h1>
        <div class="row">
            <div class="col-md-12">
                <!-- 搜索表单 -->
                <form class="form-inline mb-3" action="${pageContext.request.contextPath}/order/list" method="get">
                    <div class="form-group mr-2">
                        <input type="text" name="u_name" class="form-control" placeholder="用户姓名" value="${param.u_name}">
                    </div>
                    <div class="form-group mr-2">
                        <select name="pageSize" class="form-control" onchange="this.form.submit()">
                            <option value="5" ${pageInfo.pageSize == 5 ? 'selected' : ''}>每页5条</option>
                            <option value="10" ${pageInfo.pageSize == 10 ? 'selected' : ''}>每页10条</option>
                            <option value="20" ${pageInfo.pageSize == 20 ? 'selected' : ''}>每页20条</option>
                        </select>
                    </div>
                    <button type="submit" class="btn btn-primary">搜索</button>
                </form>
    <!-- 数据展示 -->
    <table class="table table-bordered table-hover">
        <thead>
            <tr>
                <th>订单编号</th>
                <th>用户姓名</th>
                <th>线路名称</th>
                <th>订单金额</th>
                <th>订单状态</th>
            </tr>
        </thead>
        <tbody>
            <c:forEach items="${pageInfo.list}" var="order">
                <tr>
                    <td>${order.order_id}</td>
                    <td>${order.user.u_name}</td>
                    <td>${order.route.route_name}</td>
                    <td>¥${order.orders_price}</td>
                    <td>
                        <c:choose>
                            <c:when test="${order.orders_state == 0}">待支付</c:when>
                            <c:when test="${order.orders_state == 1}">已支付</c:when>
                            <c:when test="${order.orders_state == 2}">已取消</c:when>
                            <c:otherwise>未知状态</c:otherwise>
                        </c:choose>
                    </td>
                </tr>
            </c:forEach>
        </tbody>
    </table>
                <!-- 数据统计信息 -->
                <div class="mb-3">
                    <p>总条数: ${pageInfo.total}, 当前页: ${pageInfo.pageNum}, 总页数: ${pageInfo.pages}</p>
                </div>

                <!-- 分页导航 -->
                <nav aria-label="Page navigation">
                    <ul class="pagination">
                        <!-- 首页 -->
                        <li class="page-item ${pageInfo.pageNum == 1 ? 'disabled' : ''}">
                            <a class="page-link" href="${pageContext.request.contextPath}/order/list?currentPage=1&u_name=${param.u_name}&pageSize=${pageInfo.pageSize}">首页</a>
                        </li>
                        <!-- 上一页 -->
                        <li class="page-item ${pageInfo.pageNum == 1 ? 'disabled' : ''}">
                            <a class="page-link" href="${pageContext.request.contextPath}/order/list?currentPage=${pageInfo.pageNum - 1}&u_name=${param.u_name}&pageSize=${pageInfo.pageSize}">上一页</a>
                        </li>
                        <!-- 页码 -->
                        <c:forEach begin="1" end="${pageInfo.pages}" var="i">
                            <li class="page-item ${i == pageInfo.pageNum ? 'active' : ''}">
                                <a class="page-link" href="${pageContext.request.contextPath}/order/list?currentPage=${i}&u_name=${param.u_name}&pageSize=${pageInfo.pageSize}">${i}</a>
                            </li>
                        </c:forEach>
                        <!-- 下一页 -->
                        <li class="page-item ${pageInfo.pageNum == pageInfo.pages ? 'disabled' : ''}">
                            <a class="page-link" href="${pageContext.request.contextPath}/order/list?currentPage=${pageInfo.pageNum + 1}&u_name=${param.u_name}&pageSize=${pageInfo.pageSize}">下一页</a>
                        </li>
                        <!-- 尾页 -->
                        <li class="page-item ${pageInfo.pageNum == pageInfo.pages ? 'disabled' : ''}">
                            <a class="page-link" href="${pageContext.request.contextPath}/order/list?currentPage=${pageInfo.pages}&u_name=${param.u_name}&pageSize=${pageInfo.pageSize}">尾页</a>
                        </li>
                    </ul>
                </nav>
            </div>
        </div>
    </div>
</body>
</html>